//
//  StartViewController.swift
//  麦子洗衣 启动画面
//
//  Created by yangyifan on 15/10/19.
//  Copyright © 2015年 womenshuo. All rights reserved.
//

import UIKit

class StartViewController: UIViewController, UIScrollViewDelegate {

    @IBOutlet var scrollView: UIScrollView!
    @IBOutlet var btn: UIButton!
    @IBOutlet var page: UIPageControl!
    
    private var imageArr: [String]  = ["0-引-1", "0-引-2", "0-引-3"]//引导图片
    private var bounds: CGRect      = UIScreen.mainScreen().bounds//屏幕大小
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //初始化
        self.initialize()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //初始化
    private func initialize() {
        scrollView.delegate = self
        //设置 UIScrollView 的 ContentSize 大小 和 禁止 横向 和 纵向滚动条
        self.setScrollView()
        //设置引导图片
        self.setImage()
    }
    
    //设置 UIScrollView 的 ContentSize 大小 和 禁止 横向 和 纵向滚动条
    private func setScrollView() {
        scrollView.contentSize                      = CGSize(width: self.bounds.width * CGFloat(self.imageArr.count), height: self.bounds.height)
        scrollView.showsHorizontalScrollIndicator   = false
        scrollView.showsVerticalScrollIndicator     = false
    }
    
    //设置引导图片
    private func setImage() {
        
        if self.imageArr.count <= 0 {
            return
        }
        
        //添加图片到 UIScrollView 上
        for index in  0..<self.imageArr.count {
            let image   = UIImageView(frame: CGRect(x: self.bounds.width * CGFloat(index), y: 0, width: self.bounds.width, height: self.bounds.height))
            image.image = UIImage(named: self.imageArr[index])
            scrollView.addSubview(image)
        }
        
    }
    
    //UIScrollView 滚动
    func scrollViewDidScroll(scrollView: UIScrollView) {
        page.currentPage = Int(scrollView.contentOffset.x / bounds.width)
    }

    //跳转页面 到首页
    @IBAction func redirect(sender: UIButton) {
        self.navigationController?.popViewControllerAnimated(true)
    }
}
